package nit.wave.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import nit.wave.model.Biaobai;
import nit.wave.service.BiaobaiService;
import com.google.gson.Gson;

public class getBiaobaiServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// 将请求、响应的编码均设置为UTF-8（防止中文乱码）
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		
		int type = Integer.parseInt(request.getParameter("type"));
		int start =Integer.parseInt( request.getParameter("start"));
		int length = Integer.parseInt(request.getParameter("length"));
		System.out.println(type+"+"+start+"+"+length);
		
		BiaobaiService service = new BiaobaiService();
		List<Biaobai> biaobais = service.getBiaobai(type, start, length);
		
		Gson gson = new Gson();
		String result = gson.toJson(biaobais);
		System.out.println(result);
		
		PrintWriter out = response.getWriter();
		out.print(result);
		out.close();

	}

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		this.doPost(req, resp);
	}

}
